<?php if($user->access!=0){ 





//check trie des servers
if (isset($_GET['sortby']) and $_GET['sortby'] ){$sortby = mysql_escape_string($_GET['sortby']);}
else{$sortby = mysql_escape_string('name');}

if (isset($_GET['orderby']) and $_GET['orderby'] != "" ){$orderby = mysql_escape_string($_GET['orderby']);}
else{$orderby = mysql_escape_string('ASC');}
?>
<div id="page_favorite">

<script language="javascript">
function funRemove(){
        document.form1.action="index.php?page=favorite";
}
function funWget(){
        document.form1.action="index.php?dl_txt=1";
}

function selectall(box){
	checkb=document.getElementsByName('favorite_box[]');
	t=checkb.length;
	for(var i=0; i<t; i++){
		checkb[i].checked = box.checked;
	}
} 
</script>
<?php 

$sql_query = mysql_query("SELECT ".DATABASE_TABLE_SERVER.".address,
							".DATABASE_TABLE_FILE.".name,".DATABASE_TABLE_FAV.".fullpath,
							".DATABASE_TABLE_FAV.".id,".DATABASE_TABLE_FILE.".server,".DATABASE_TABLE_FILE.".taille
							FROM ".DATABASE_TABLE_FAV." 
							LEFT JOIN ".DATABASE_TABLE_FILE." ON ".DATABASE_TABLE_FAV.".fullpath = ".DATABASE_TABLE_FILE.".fullpath 
							LEFT JOIN ".DATABASE_TABLE_SERVER." ON  ".DATABASE_TABLE_SERVER.".name = ".DATABASE_TABLE_FILE.".server 
							WHERE ".DATABASE_TABLE_FAV.".user = '".$user->login."' ORDER BY ".DATABASE_TABLE_FILE.".".$sortby." ".$orderby);
if (mysql_num_rows($sql_query)>=1){

?>

<form name="form1" action= "index.php?page=favorite" method="post">
<table>
<caption>Favorites</caption>
<tr>
	<td class="title">Title</td>
	<td class="title"><a href="index.php?page=<?php print $_GET['page']; ?>&orderby=<?php if($orderby=='ASC'){print 'DESC';}else{print 'ASC';}?>&sortby=taille">Size</a></td>
	<td class="title"><a href="index.php?page=<?php print $_GET['page']; ?>&orderby=<?php if($orderby=='ASC'){print 'DESC';}else{print 'ASC';}?>&sortby=server">Server</a></td>
</tr>
<?php
			while ($query = mysql_fetch_array($sql_query) ){
?>
<?php if ($query['server']!=""){ ?>
<tr bgcolor="#ffffff" onmouseout="this.bgColor='#FFFFFF';" onmouseover="this.bgColor='#D0E8F8';" >
<?php }else{?>
<tr bgcolor="#ef8e74">
<?php }?>	
	<td>
		<input type="checkbox" name="favorite_box[]" value="<?php print $query['id']; ?>" />
		<a target="_blank" href="http://www.allocine.fr/recherche/?motcle=<?php print File::rm_ext($query['name']) ?>&x=0&y=0&rub=0" >
			<img style="border:0;" src="img/allo.ico" alt="BA"/>
		</a>
		<?php if ($query['server']!=""){ ?>
		<a  href="index.php?film=<?php print md5($query['fullpath']); ?>&idserver=<?php print $query['server']; ?>&page=<?php print $_GET['page']; ?>&server=<?php print $_GET['server']; ?>" 
					onmouseover="this.innerHTML=this.innerHTML+'<?php print htmlspecialchars(stripslashes(str_replace("'","\'",File::get_ext(File::get_name_with_fullpath($query['fullpath'])))));?>'" 
					onmouseout="this.innerHTML='<?php print htmlspecialchars(stripslashes(File::rm_ext(str_replace("'","\'",File::get_name_with_fullpath($query['fullpath'])))));?>'"
		>
			<?php print htmlspecialchars(stripslashes(File::rm_ext(File::get_name_with_fullpath($query['fullpath']))));?>
		</a>
		<?php }else{?>
		<span onmouseover="this.innerHTML='<?php print htmlspecialchars(stripslashes(str_replace("'","\'",File::get_name_with_fullpath($query['fullpath']))));?>'" 
					onmouseout="this.innerHTML='<?php print htmlspecialchars(stripslashes(File::rm_ext(str_replace("'","\'",File::get_name_with_fullpath($query['fullpath'])))));?>'"><?php print htmlspecialchars(stripslashes(File::rm_ext(File::get_name_with_fullpath($query['fullpath']))));?></span>
	<?php }?>
	</td>
	<td>
	<?php if ($query['server']!=""){ print File::size_modif($query['taille']); }else{ print "Indisponible"; } ?>
	</td>
	<td name="<?php print Server::mise_en_forme_address($query['address']);?>"><?php if ($query['server']==""){print "Indisponible";}else{print $query['server'];} ?></td>
	
</tr>
<?php } ?>
	<tr>
		<td class="center" colspan="3">
			<input type="checkbox" onclick="selectall(this);"/>select/deselect all
		</td>
	</tr>
	<tr>
		<td class="center" colspan="3">
			<input type="hidden" name="action" value="remove_favorite" />
			<input type="submit" name="wget" value="Wget" onclick="funWget();" />
			<input type="submit"  name="remove" value="Remove" onclick="funRemove()"/>
		</td>
	</tr>
</table>
</form>
<?php
}else{
?>
<div class="title" style="text-align:center; margin: auto auto;">No favorite file</div>
<?php
}
//gestion de la couleur des serveur down
	$sql_query=mysql_query("Select address from ".DATABASE_TABLE_SERVER." ORDER BY `name` ASC");
	$javascript_string="";
	while ($query = mysql_fetch_array($sql_query)){
		$javascript_string = $javascript_string."\"".Server::mise_en_forme_address($query['address'])."\",";
	}
	$javascript_string = substr($javascript_string,0,-1);
	?>
	<script>
		var arrayserv = new Array(<?php print $javascript_string; ?>);
		info_serv_up(arrayserv);
	</script>
</div>


<?php 
}
?>